//
//  BaseTabBarViewController.m
//  WuliHanhan
//
//  Created by chen tang on 16/2/25.
//  Copyright © 2016年 LVpeng. All rights reserved.
//

#import "BaseTabBarViewController.h"
#import "Header.h"
#import "ThreeViewController.h"



@interface BaseTabBarViewController ()


@property (nonatomic, strong) UIButton *button1;
@property (nonatomic, strong) UIButton *button2;
@property (nonatomic, strong) UIButton *button3;
@property (nonatomic, strong) UIButton *button4;
@property (nonatomic, strong) UIButton *button5;




@property (nonatomic, strong) UILabel *lable1;
@property (nonatomic, strong) UILabel *lable2;
@property (nonatomic, strong) UILabel *lable3;
@property (nonatomic, strong) UILabel *lable4;

@property (nonatomic, strong) NSArray *lableArray;



@property (nonatomic, assign) int writeSelectIndex;

@end

@implementation BaseTabBarViewController

- (void)loadView
{
    [super loadView];
    
    [self.navigationController setNavigationBarHidden:YES];
    
    
    _button1 = [UIButton buttonWithType:UIButtonTypeCustom];
    [_button1 setFrame:CGRectMake(0, heightView-55, WithView/5.0, 50.0)];
    [_button1.titleLabel setText:@"one"];
//    [_button1 setBackgroundColor:[UIColor grayColor]];
    [self.view addSubview:_button1];
    
    
    _button2 = [UIButton buttonWithType:UIButtonTypeCustom];
    [_button2.titleLabel setText:@"two"];
    [_button2 setFrame:CGRectMake(WithView/5.0, heightView-55, WithView/5.0, 50.0)];
//    [_button2 setBackgroundColor:[UIColor redColor]];
    [self.view addSubview:_button2];

    _button3 = [UIButton buttonWithType:UIButtonTypeCustom];
    [_button3 setFrame:CGRectMake(WithView/5.0+WithView/5.0, heightView - 50, WithView/5.0, 50.0)];
    [_button3.titleLabel setText:@"three"];
//    [_button3 setBackgroundColor:[UIColor yellowColor]];
    [self.view addSubview:_button3];
    
    _button4 = [UIButton buttonWithType:UIButtonTypeCustom];
    [_button4 setFrame:CGRectMake(WithView/5.0+WithView/5.0+WithView/5.0, heightView-55, WithView/5.0, 50.0)];
    [_button4.titleLabel setText:@"four"];
//    [_button4 setBackgroundColor:[UIColor redColor]];
    [self.view addSubview:_button4];

    _button5 = [UIButton buttonWithType:UIButtonTypeCustom];
    [_button5 setFrame:CGRectMake(WithView/5.0+(WithView/5.0)*3.0, heightView-55, WithView/5.0, 50.0)];
    [_button5.titleLabel setText:@"five"];
//    [_button5 setBackgroundColor:[UIColor blueColor]];
    [self.view addSubview:_button5];

    
    
    UIImage *image = nil;
    
    image = [UIImage imageNamed:@"shouye"];
    [_button1 setImage:image forState:UIControlStateNormal];
    image = [UIImage imageNamed:@"shouyexuanze"];
    [_button1 setImage:image forState:UIControlStateSelected];
    
    image = [UIImage imageNamed:@"guanzhu"];
    [_button2 setImage:image forState:UIControlStateNormal];
    image = [UIImage imageNamed:@"guanzhuxuanze"];
    [_button2 setImage:image forState:UIControlStateSelected];
    
    image = [UIImage imageNamed:@"chuangzuo"];
    [_button3 setImage:image forState:UIControlStateNormal];
    image = [UIImage imageNamed:@"chuangzuo"];
    [_button3 setImage:image forState:UIControlStateSelected];

    image = [UIImage imageNamed:@"sucai"];
    [_button4 setImage:image forState:UIControlStateNormal];
    image = [UIImage imageNamed:@"sucaixuanze"];
    [_button4 setImage:image forState:UIControlStateSelected];

    image = [UIImage imageNamed:@"geren"];
    [_button5 setImage:image forState:UIControlStateNormal];
    image = [UIImage imageNamed:@"gerenxuanze"];
    [_button5 setImage:image forState:UIControlStateSelected];

    
    [_button1 setTag:1];
    [_button2 setTag:2];
    [_button3 setTag:3];
    [_button4 setTag:4];
    [_button5 setTag:5];
    
    [_button1 addTarget:self action:@selector(hidenTabbar:) forControlEvents:UIControlEventTouchUpInside];
    [_button2 addTarget:self action:@selector(hidenTabbar:) forControlEvents:UIControlEventTouchUpInside];
    [_button3 addTarget:self action:@selector(hidenTabbar:) forControlEvents:UIControlEventTouchUpInside];
    [_button4 addTarget:self action:@selector(hidenTabbar:) forControlEvents:UIControlEventTouchUpInside];
    [_button5 addTarget:self action:@selector(hidenTabbar:) forControlEvents:UIControlEventTouchUpInside];
    
    
    _writeSelectIndex = 0;
    
    
//    _lableArray = @[_lable1, _lable2, _lable3, _lable4];
    
    _lable1 = [[UILabel alloc] initWithFrame:CGRectMake(12, heightView - 10, 40, 5)];
    [_lable1 setText:@"首页"];
    [_lable1 setTextAlignment:NSTextAlignmentCenter];
    _lable1.font = [UIFont fontWithName:@"Arial" size:10];
    [self.view addSubview:_lable1];
    
    _lable2 = [[UILabel alloc] initWithFrame:CGRectMake(WithView/5.0 + 12, heightView - 10, 40, 5)];
    [_lable2 setText:@"关注"];
    [_lable2 setTextAlignment:NSTextAlignmentCenter];
    _lable2.font = [UIFont fontWithName:@"Arial" size:10];
    [self.view addSubview:_lable2];
    
    _lable3 = [[UILabel alloc] initWithFrame:CGRectMake(WithView/5.0 * 3 + 12, heightView - 10, 40, 5)];
    [_lable3 setText:@"素材库"];
    [_lable3 setTextAlignment:NSTextAlignmentCenter];
    _lable3.font = [UIFont fontWithName:@"Arial" size:10];
    [self.view addSubview:_lable3];
    
    _lable4 = [[UILabel alloc] initWithFrame:CGRectMake(WithView/5.0  * 4 + 12, heightView - 10, 40, 5)];
    [_lable4 setText:@"我的"];
    [_lable4 setTextAlignment:NSTextAlignmentCenter];
    _lable4.font = [UIFont fontWithName:@"Arial" size:10];
    [self.view addSubview:_lable4];
    
}



- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}



- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [_button1 setHidden:NO];
    [_button2 setHidden:NO];
    [_button3 setHidden:NO];
    [_button4 setHidden:NO];
    [_button5 setHidden:NO];

}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}




- (void)removeSelect
{
    [_button1 setSelected:NO];
    [_button2 setSelected:NO];
    [_button4 setSelected:NO];
    [_button5 setSelected:NO];
    
    [_lable1 setTextColor:uicolor(119, 119, 119)];
    [_lable2 setTextColor:uicolor(119, 119, 119)];
    [_lable3 setTextColor:uicolor(119, 119, 119)];
    [_lable4 setTextColor:uicolor(119, 119, 119)];
}




- (void)hidenTabbar:(UIButton *)sender
{
    if (sender.tag == 3)
    {
//        [_button1 setHidden:YES];
//        [_button2 setHidden:YES];
//        [_button3 setHidden:YES];
//        [_button4 setHidden:YES];
//        [_button5 setHidden:YES];

        ThreeViewController *three = [[ThreeViewController alloc] init];
        UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:three];
        [self.view.window.rootViewController presentViewController:nav animated:YES completion:nil];

    }
    else
    {
        self.selectedIndex = sender.tag-1;
        [self removeSelect];
        [sender setSelected:YES];
        
//        UILabel *lable = [_lableArray objectAtIndex:sender.tag-1];
//        [lable setTextColor:uicolor(181, 180, 181)];
        [self selectedCustomTabar];
    }
    
    
////    [self.tabBarController setHidesBottomBarWhenPushed:YES];
//    [self.tabBar setHidden:YES];
////    [self setHidesBottomBarWhenPushed:YES];
    
    
}

- (void)selectedCustomTabar{
    
    if (_button1.selected) {
        [_lable1 setTextColor:uicolor(34, 34, 34)];
    }else if (_button2.selected){
        [_lable2 setTextColor:uicolor(34, 34, 34)];
    }else if (_button4.selected){
        [_lable3 setTextColor:uicolor(34, 34, 34)];
    }else if (_button5.selected){
        [_lable4 setTextColor:uicolor(34, 34, 34)];
    }
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
